package com.czk.interfaces;

import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/5/17 11:07
 */
@Component
public class ITableSharedStrategyDate implements ITableSharedStrategy {
    private static final String DATE_PATTERN = "yyyyMM";

    @Override
    public String generateTableName(String prefix, Object value) {
        // 验证
        verificationTableNamePrefix(prefix);
        if (value == null || Objects.equals("", value)) {
            return prefix + "_" + new SimpleDateFormat(DATE_PATTERN).format(new Date());
        } else {
            return prefix + "_" + new SimpleDateFormat(value.toString()).format(new Date());
        }
    }
}
